﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Site.Master" AutoEventWireup="true" CodeBehind="ExperimentManagement.aspx.cs" Inherits="BEELab.ExperimentManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server">
    <div id="wrap" class="clearfix">
        <div class="block">
            <h2 class="headline">Experiment Management</h2>
            <div class="dashboard-hold">

                <div id="new-experiment" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none">
                    <asp:Label ID="lblID" runat="server" Visible="false"></asp:Label>

                    <asp:Label ID="lblNew" runat="server" Visible="true"> <h2 class="headline">New Experiment</h2></asp:Label>

                    <asp:Label ID="lblEdit" runat="server" Visible="false"> <a id="btnBack" runat="server" class="back-btn" href="javascript:;">Back</a> <h2 class="headline">Experiment Design/Edit</h2></asp:Label>
                    <div class="sign-form">
                        <div class="input-hold">
                            <asp:Label ID="Label1" CssClass="sign-label" AssociatedControlID="txtName" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="txtName" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvtxtName" CssClass="field-validation-error" ControlToValidate="txtName" ValidationGroup="AddExperimentGroup" runat="server" ErrorMessage="* Name is required." Text="*"></asp:RequiredFieldValidator>
                        </div>
                        <div class="input-hold">
                            <asp:Label ID="Label2" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                            <asp:TextBox CssClass="text-area" ID="txtDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvtxtDescription" Display="Dynamic" ControlToValidate="txtDescription" ValidationGroup="AddExperimentGroup" runat="server" ErrorMessage="* Description is required" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button CssClass="sign-submit" ValidationGroup="AddExperimentGroup" runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary runat="server" ID="vsNewExperiment" ValidationGroup="AddExperimentGroup" CssClass="field-validation-error" />
                        <p>&nbsp;</p>
                    </div>
                </div>

                <h3>Experiment List</h3>
                <a href="#new-experiment" class="abbtn fancybox">New Experiment</a>
            </div>
            <asp:Label ID="lblUpdateMessage" runat="server" Visible="false" ForeColor="Red"></asp:Label>
            <asp:GridView ID="gvExperiment" runat="server" AutoGenerateColumns="False" CssClass="dash-col" DataSourceID="SqlDataSource1" DataKeyNames="ID" OnRowDeleting="gvExperiment_RowDeleting" AllowPaging="True" AllowSorting="True">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="8%" SortExpression="ID" InsertVisible="False" ReadOnly="True" Visible="False" >
                    <ItemStyle Width="8%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                    <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
                    <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditExperiment.aspx?ID={0}" Text="Edit" />
                    <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="DuplicateExperiment.aspx?ID={0}" Text="Duplicate" />
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" SelectCommand="SELECT [Programs].[ID],[Name],[Description],[Users].[Email] AS Owner FROM [Programs] JOIN [Users] ON Programs.OwnerID=Users.ID WHERE ( (([OwnerID] = @OwnerID) OR ('True'=@IsAdmin)) AND ([Type] = @Type))" DeleteCommand="DELETE FROM Programs WHERE ID=@Param1">
                <DeleteParameters>
                    <asp:ControlParameter ControlID="gvExperiment" Name="Param1" PropertyName="SelectedValue" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:SessionParameter Name="OwnerID" SessionField="UserID" Type="Int32" />
                    <asp:SessionParameter Name="IsAdmin" SessionField="Admin" Type="String" />
                    <asp:Parameter DefaultValue="Experiment" Name="Type" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $("a[class='abbtn fancybox']").fancybox();
            $('a[href*="DuplicateExperiment.aspx?ID="]').fancybox({ 'type': 'iframe', 'width': '710px' });

            $('a').filter(function (index) { return $(this).text() === "Delete"; }).click(function () { return confirm('Are you sure you want to delete this item?'); })
        });
    </script>
</asp:Content>
